package com.zhq.okhttp;

import android.util.ArrayMap;


import com.zhq.apputil.utils.LogUtil;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

/**
 *
 */
public class ApiServer extends RetrofitUtils {
    protected static NetService service;
    //设缓存有效期为1天
    protected static final long CACHE_STALE_SEC = 60 * 60 * 24 * 1;
    //查询缓存的Cache-Control设置，使用缓存
    protected static final String CACHE_CONTROL_CACHE = "only-if-cached, max-stale=" + CACHE_STALE_SEC;
    //查询网络的Cache-Control设置。不使用缓存
    protected static final String CACHE_CONTROL_NETWORK = "max-age=0";

    public static NetService getNetService() {
        if (LogUtil.isDEBUG()) {
            return getRetrofit().create(NetService.class);
        } else {
            service = getRetrofit().create(NetService.class);
        }
        return service;
    }

    public interface NetService {


        @POST("app_user/login")
        Observable<ResponseBody> loginUser(@Body ArrayMap<String, String> mp);

        @POST("app_workmonitor/getWorkmonitorInfo")
        Observable<ResponseBody> getHomeDataList(@Body ArrayMap<String, Object> mp);


        @GET("app_user/loginOut")
        Observable<ResponseBody> logoutUser();

        @POST("api/v1/autoLoginUser")
        Call<ResponseBody> getRefreshToken(@Body ArrayMap<String, String> mp);//自动登录


        @GET("app_user/saveHeadPicture")
        Observable<ResponseBody> saveHeadPicture(@Query("pictureId") Integer pictureId);//头像保存


        @GET("app_workmonitor/getBatteryAndlls")
        Observable<ResponseBody> getSubstationTreeList(@Query("id") Integer id);//获取储能电站加载树


        @GET("app_workmonitor/getSubInfoById")
        Observable<ResponseBody> getSubstationId(@Query("id") Integer id);//获取变电站详情

        @GET("app_workmonitor/getPEchartLine")
        Observable<ResponseBody> getPEchartLine(@Query("id") Integer id);//获取有功功率曲线

        @GET("app_workmonitor/getQEchartLine")
        Observable<ResponseBody> getQEchartLine(@Query("id") Integer id);//获取无功功率曲线


        @GET("app_workmonitor/getStationDById")
        Observable<ResponseBody> getStationDById(@Query("id") Integer id);//储能单元获取变流器电池组明细


        @POST("app_workmonitor/getPcsByConId")
        Observable<ResponseBody> getPcsByConId(@Query("id") Integer id);//根据变流器ID获取遥测遥信


        @POST("app_alarm/alarmListByOrg")
        Observable<ResponseBody> alarmListByOrg(@Body ArrayMap<String, Object> mp);//告警列表


        @GET("app_alarm/getSubstationList")
        Observable<ResponseBody> getSubstationList();//获取电站列表

        @POST("app_alarm/deviceOrgInfo")
        Observable<ResponseBody> getDeviceList(@Body ArrayMap<String, Object> mp);//根据站点id获取所需设备(下拉)

        @POST("app_alarm/alarmInfo")
        Observable<ResponseBody> getAlarmInfo(@Body ArrayMap<String, Object> mp);//告警信息支持查询参数


        @POST("app_user/getMessageList")
        Observable<ResponseBody> getMessageList(@Body ArrayMap<String, Object> mp);//我的消息列表

        @GET("app_user/changeUserRecived")
        Observable<ResponseBody> readUnMessage(@Query("messageId") Integer messageId);//已读未读消息

        @GET("app_user/getAppRecived")
        Observable<ResponseBody> getAppRecived();//获取需要推送的消息列表（用于轮询）

        @POST("app/workorder/workOrderListInfo")
        Observable<ResponseBody> getWorkOrderList(@Body ArrayMap<String, Object> mp);//获取我的工单列表


        @POST("app/workorder/workOrderDetail")
        Observable<ResponseBody> getWorkOrderDetail(@Body ArrayMap<String, Object> mp);//工单详情



        @POST("app/workorder/getWorkerByLeader")
        Observable<ResponseBody> getWorkOrderExecuteUser();//获取组员信息



        @POST("app/workorder/examineWorkOrder")
        Observable<ResponseBody> receiveWorkOrder(@Body ArrayMap<String, Object> map);//接受工单


        @POST("app/workorder/uploadWorkOrder")
        Observable<ResponseBody> uploadWorkOrder(@Body ArrayMap<String, Object> map);//上传工单记录


        @POST("app/workorder/distributeWorkOrder")
        Observable<ResponseBody> distributeWorkOrder(@Body ArrayMap<String, Object> map);//审核工单



        @POST("app/workorder/confirmWorkOrder")
        Observable<ResponseBody> sureWorkOrderComplete(@Body ArrayMap<String, Object> map);//工单已确认


        @POST("app_user/updatePassword")
        Observable<ResponseBody> updatePassword(@Body ArrayMap<String, Object> map);//设置密码

        @POST("app_picture/WorkingConditionPictureList")
        Observable<ResponseBody> getSvgList(@Body ArrayMap<String, Object> map);//获取svg图列表


        @Multipart
        @POST("app_sysmgt/file/uploadOrderPictureFile")
        Observable<ResponseBody> uploadMultipleFiles(@Part MultipartBody.Part file1);  // 上传文件


        @Multipart
        @POST("app_sysmgt/file/uploadHeadSculptureFile")
        Observable<ResponseBody> uploadHeadSculptureFile(@Part MultipartBody.Part file1);  // 上传用户头像

        @Streaming
        @GET
        /**
         * 大文件官方建议用 @Streaming 来进行注解，不然会出现IO异常，小文件可以忽略不注入
         */
        Observable<ResponseBody> downloadFile(@Url String fileUrl);





        @GET("api/v1/getHeatSubstationBoilerTelemetryModel")
        Observable<ResponseBody> getHeatSubstationBoilerTelemetryModel(@Query("substationId") int id, @Query("deviceCode") String deviceCode);//获取厂站详情


        @GET("api/v1/getTelemetryDeviceList")
        Observable<ResponseBody> getTelemetryDeviceList(@Query("substationId") int substationId,
                                                        @Query("pageNum") int pageNum, @Query("pageSize") int pageSize);//获取变电站采样点详情

        @GET("api/v1/getDeviceYaoXinRealDataList")
            //分页获取设备下遥信点
        Observable<ResponseBody> getDeviceYaoXinRealDataList(@Query("substationId") int substationId,
                                                             @Query("deviceCode") String deviceCode, @Query("pageNum") int pageNum, @Query("pageSize") int pageSize);//分页获取设备下遥信点

        @GET("api/v1/getDeviceYaoCeRealDataList")
            //分页获取设备下遥测点
        Observable<ResponseBody> getDeviceYaoCeRealDataList(@Query("substationId") int substationId,
                                                            @Query("deviceCode") String deviceCode, @Query("pageNum") int pageNum, @Query("pageSize") int pageSize);//分页获取设备下遥测点

        @GET("api/v1/getYaoXinRealDataList")
            //分页获取直属遥信点
        Observable<ResponseBody> getZhiShuYaoXinRealDataList(@Query("substationId") int substationId,
                                                             @Query("pageNum") int pageNum, @Query("pageSize") int pageSize);//分页获取设备下遥信点

        @GET("api/v1/getYaoCeRealDataList")
            //分页获取直属遥测点
        Observable<ResponseBody> getZhiShuYaoCeRealDataList(@Query("substationId") int substationId,
                                                            @Query("pageNum") int pageNum, @Query("pageSize") int pageSize);//分页获取设备下遥测点


        @GET("api/v1/getEnergyStorageBaseInfoDeatail")
        Observable<ResponseBody> getEnergyStorageBaseInfoDetail(@Query("id") int id);//获取储能台账详情

        @GET("api/v1/getHeatorageBaseInfoDeatail")
        Observable<ResponseBody> getHeatStorageBaseInfoDeatail(@Query("id") int id);//储热厂站台账信息

        @GET("api/v1/getTransformerRoomDetail")
        Observable<ResponseBody> getTransformerRoomDetail(@Query("id") int id);//获取电房台账信息

        @POST("api/v1/getTelemetryHistoryData")
        Observable<ResponseBody> getTelemetryHistoryData(@Body ArrayMap<String, Object> map);//分页获取采样点历史数据

        @GET("api/v1/getHeatMonthStatistics")
        Observable<ResponseBody> getHeatMonthStatistics(@Query("queryMonth") String queryMonth,
                                                        @Query("substationId") Integer substationId);//获取月统计


        @GET("api/v1/getSubstationDayAlarmCount")
        Observable<ResponseBody> getSubstationDayAlarmCount(@QueryMap ArrayMap<String, Object> mp);//获取日告警统计数量

        @GET("api/v1/getSubstationDayAlarmList")
        Observable<ResponseBody> getSubstationDayAlarmList(@QueryMap ArrayMap<String, Object> mp);//获取日告警统计
    }

}
